package com.itheima.mapper;

import com.itheima.domain.dto.LoginDTO;
import com.itheima.domain.pojo.Emp;
import com.itheima.domain.query.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author: Sch
 * @Date: 2025/07/11 15:31
 * @Description:
 */
@Mapper
public interface EmpMapper {
    /**
     * 查询总记录数
     */
    @Select("select count(*) from emp e left join dept d on e.dept_id = d.id ")
    public Long count();

    /**
     * 查询所有的员工及其对应的部门名称
     */
    /*@Select("select e.*, d.name deptName from emp as e left join dept as d on e.dept_id = d.id limit #{start}, #{pageSize}")
    public List<Emp> list(@Param("start") Integer start ,@Param("pageSize") Integer pageSize);
*/
    /*@Select("select e.*,d.name depeName from emp as e left join dept as d on e.dept_id = d.id")
    public List<Emp> list();*/
    /* public List<Emp> list(@Param("name") String name, @Param("gender") Integer gender, @Param("begin") LocalDate begin, @Param("end") LocalDate end);*/

    //查询所有的员工及其对应的部门名称
    List<Emp> list(EmpQueryParam empQueryParam);

    //添加员工
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username,password,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) values(#{username},#{password},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    //查询所有的员工及其对应的部门名称
    @Select("select name,id from emp where job = 1")
    List<Emp> findAll();

   //批量删除员工
    void deleteByIds(@Param("ids") List<Integer> ids);

    Emp getById(Integer id);


    void updateById(Emp emp);


    /**
     * 统计各个职位的员工人数
     */
    @MapKey("pos")
    List<Map<String,Object>> countEmpJobData();

    /**
     * 统计员工性别信息
     */
    @MapKey("name")
    List<Map> countEmpGenderData();


    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp getUsername(LoginDTO loginDTO);
}
